package com.squid.templateProject.controller;

import com.squid.templateProject.bean.Return;
import com.squid.templateProject.bean.req.PageReq;
import com.squid.templateProject.bean.req.user.UserInsertUpdateReq;
import com.squid.templateProject.bean.req.user.UserSelectPageReq;
import com.squid.templateProject.bean.resp.PageResp;
import com.squid.templateProject.bean.resp.user.UserSelectPageResp;
import com.squid.templateProject.service.user.UserEntityService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * Description
 *
 * @author jinhang
 * @since 2024-1-24
 **/
@RestController
@RequestMapping(value = "user")
public class UserController {
    @Resource
    UserEntityService userEntityService;

    @PostMapping("insertUser")
    public Return<Object> insertUser(@RequestBody @Validated UserInsertUpdateReq req) {
        userEntityService.insertUser(req);
        return Return.success();
    }

    @PostMapping("updateUser")
    public Return<Object> updateUser(@RequestBody @Validated UserInsertUpdateReq req) {
        userEntityService.updateUser(req);
        return Return.success();
    }

    @PostMapping("deleteUser")
    public Return<Object> deleteUser(@RequestParam @NotBlank(message = "id不能为空") String id) {
        userEntityService.deleteUser(id);
        return Return.success();
    }

    @PostMapping("pageUser")
    public Return<PageResp<UserSelectPageResp>> pageUser(@RequestBody @Validated PageReq<UserSelectPageReq> req) {
        PageResp<UserSelectPageResp> response = userEntityService.pageUser(req);
        return Return.<PageResp<UserSelectPageResp>>success().data(response);
    }
}
